package cn.itcast.demo.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Slf4j
public class PayTokenGatewayFilter implements GatewayFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
            //获取请求路径
            ServerHttpRequest request = exchange.getRequest();
            String token = request.getHeaders().getFirst("token");
            log.info("PayTokenGatewayFilter token:{}",token);
            request.mutate().header("message","PayTokenGatewayFilterFactory");
            request.mutate().header("token",token);
            return chain.filter(exchange);
    }
}